<template>
    <div id="advantage">
        <!-- 这是应聘优势页面 -->
      <div class="Header-wrapper">
            <yd-navbar title="填写应聘优势" fontsize="16px" color="#fff" height="45px" bgcolor="#ffd602">
                <div slot="left" @click="golink">
                    <i class="iconfont icon-back Fcolor" ></i>
                </div>
                <div class="release-right" slot="right" @click="save">保存</div>
            </yd-navbar>
        </div>
        <div class="advantage-wrapper">
            <div class="advantage-box-detail">
                <p class='advantage-box-detail-p'><i>*</i>应聘优势:</p>
                <p class="EducationalExperience-texert">
                    <yd-textarea slot="right" placeholder="请输入您的实践经验" maxlength="800" v-model="ypys"></yd-textarea>
                </p>
            </div>
                <div class="advantage-box-foot">
                注: 需要填写打*号内容才能保存哦!
                </div>
            </div>
    </div>
</template>
<script type="text/ecmascript-6">
import apis from '../../../../../static/js/apis.js'
export default {
  data () {
    return {
      itemData: [],
      ypys: ''
    }
  },
  components: {
    apis
  },
  created () {
    this.id = this.$route.query.id
    if (this.id !== '' && this.id !== undefined) {
      this.$axios.post(apis + '/app/ypys/getinfo', this.confusion(JSON.stringify({
        id: this.id + ''
      })),
      {
        headers: {
          Authorization: 'Bearer ' + JSON.parse(window.localStorage.getItem('userInfo')).token,
          'Content-Type': 'application/json;charset=UTF-8',
          'Cache-Control': 'no-cache',
          isApp: 'isApp'
        }
      }
      )
        .then(response => {
          this.itemData = response.data
          // console.log(this.itemData)
          this.ypys = this.itemData.ypys
        })
        .catch(error => {
          console.log(error)
          this.$dialog.toast({
            mes: '服务器异常'
          })
        })
    }
  },
  methods: {
    golink () {
      window.history.go(-1)
    },
    save () {
      // alert(this.ypys)
      if (this.ypys === '' || this.ypys === undefined) {
        this.$dialog.toast({
          mes: '请输入应聘优势'
        })
        return false
      } else if ((this.id !== '') && (this.id !== undefined)) {
        this.$axios
          .post(
            apis + '/app/ypys/edit',
            this.confusion(
              JSON.stringify({
                id: this.id,
                ypys: this.ypys
              })
            ),
            {
              headers: {
                Authorization: 'Bearer ' + JSON.parse(window.localStorage.getItem('userInfo')).token,
                'Content-Type': 'application/json;charset=UTF-8',
                'Cache-Control': 'no-cache',
                isApp: 'isApp'
              }
            }
          )
          .then(response => {
            this.itemData = response.data
            // console.log(this.itemData)
            this.ypys = this.itemData.ypys
            this.$dialog.toast({
              mes: '修改成功',
              callback: () => {
                window.history.go(-1)
              }
            })
          })
          .catch(error => {
            console.log(error)
            this.$dialog.toast({
              mes: '服务器异常'
            })
          })
      } else {
        this.$axios
          .post(
            apis + '/app/ypys/save',
            this.confusion(
              JSON.stringify({
                ypys: this.ypys
              })
            ),
            {
              headers: {
                Authorization: 'Bearer ' + JSON.parse(window.localStorage.getItem('userInfo')).token,
                'Content-Type': 'application/json;charset=UTF-8',
                'Cache-Control': 'no-cache',
                isApp: 'isApp'
              }
            }
          )
          .then(response => {
            this.$dialog.toast({
              mes: '保存成功',
              callback: () => {
                window.history.go(-1)
              }
            })
          })
          .catch(error => {
            console.log(error)
            this.$dialog.toast({
              mes: '服务器异常'
            })
          })
      }
    }
  }
}
</script>
<style scoped>
.icon-back {
  font-size: 24px;
}
.Fcolor {
  color: #fff;
}
.release-right {
  font-size: 12px;
  color: #fff;
}
.advantage-box-foot {
  margin: 10px;
  color: #ff5b5b;
}
.advantage-wrapper {
  width: 100%;
  background: #fff;
  overflow: hidden;
}
.advantage-box-detail {
  border: 1px solid #dfdfdf;
  margin-bottom: 20px;
  padding: 20px 12px;
}
.advantage-box-detail-p {
  font-size: 14px;
  color: #333;
}
.advantage-box-detail-p i {
  color: red;
}
</style>
